dnl Process this file with autoconf to produce a configure script.
AC_INIT(kaffe)

dnl Find the machine type and setup the relevant links
AC_CANONICAL_HOST
changequote(<<, >>)dnl
case "$host_cpu-$host_os" in
i[345]86-freebsd2*)
	host_cpu=i386 ; host_os=freebsd2 ;;
i[345]86-linux*)
	host_cpu=i386 ; host_os=linux ; kaffe_share=-rdynamic ;;
i[345]86-netbsd*)
	host_cpu=i386 ; host_os=netbsd1 ;;
i[345]86-solaris2*)
	host_cpu=i386 ; host_os=solaris2 ;;
*)
	AC_MSG_ERROR(Architecture not supported)
esac
changequote([, ])dnl

AC_SUBST(kaffe_share)
AC_LINK_FILES(config/$host_cpu-asm.h config/$host_cpu-needs.h config/$host_cpu-kaffe.def config/$host_cpu-$host_os-md.h, kaffe/asm.h kaffe/needs.h kaffe/kaffe.def kaffe/md.h)

dnl Checks for programs.
AC_PROG_CC
AC_PROG_LN_S
AC_PROG_INSTALL
AC_PROG_MAKE_SET

dnl Checks for libraries.
AC_CHECK_LIB(dl,dlopen)

dnl Checks for header files.
AC_HEADER_STDC
AC_CHECK_HEADERS(fcntl.h sys/time.h unistd.h)

dnl Checks for typedefs, structures, and compiler characteristics.
AC_HEADER_TIME
AC_STRUCT_TM

dnl Checks for library functions.
AC_TYPE_SIGNAL
AC_CHECK_FUNCS(select socket)

dnl Some dynamic library need an underscore on the loading name, some don't
AC_MSG_CHECKING(for underscore in dlsym)
echo "#define _LIBC_ \"`ls /usr/lib/libncurses.so.* | head -1`\"" >> confdefs.h
AC_TRY_RUN(main() {[void* lib = (void*)dlopen(_LIBC_); if (dlsym(lib, "_initscr") != 0) { exit(0); } else { exit(1); } }], [AC_MSG_RESULT(yes); echo "#define NEED_DYN_UNDERSTORE 1" >> confdefs.h], AC_MSG_RESULT(no), exit 1)

dnl Configure lib seperately, but add in the other directories for make.
AC_CONFIG_SUBDIRS(lib)
subdirs="kaffe2native kaffe kaffeh sun include man scripts $subdirs"

AC_CONFIG_HEADER(kaffe/config.h)
AC_OUTPUT(Makefile kaffe/Makefile kaffe2native/Makefile kaffeh/Makefile sun/Makefile include/Makefile man/Makefile scripts/Makefile)

dnl Generate example environment
libdir=`eval echo $libdir` ; libdir=`eval echo $libdir`
bindir=`eval echo $bindir` ; bindir=`eval echo $bindir`
datadir=`eval echo $datadir`
echo CLASSPATH=.:$datadir/kaffe/classes.zip > ENVIRONMENT
echo KAFFEHOME=$datadir/kaffe >> ENVIRONMENT
echo LD_LIBRARY_PATH=\$LD_LIBRARY_PATH:$libdir >> ENVIRONMENT
echo PATH=\$PATH:$bindir >> ENVIRONMENT
echo export CLASSPATH KAFFEHOME LD_LIBRARY_PATH PATH >> ENVIRONMENT
